package com.example.demo.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import org.springframework.stereotype.Service;

@Service
public class UserService extends ServiceImpl<UserMapper, User> {

    // 新增
    public boolean saveUser(User user) {
        return save(user);
    }

    // 删除
    public boolean removeUserById(Long id) {
        return removeById(id);
    }

    // 更新
    public boolean updateUser(User user) {
        return updateById(user);
    }

    // 单查
    public User getUserById(Long id) {
        return getById(id);
    }

    // 分页查询
    public IPage<User> getUserPage(int pageNum, int pageSize, String name) {
        Page<User> page = new Page<>(pageNum, pageSize);
        return baseMapper.selectPageWithCondition(page, "%" + name + "%");
    }
}